using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
/// Summary description for LoaiTaiKhoanDAO
/// </summary>
public class LoaiTaiKhoanDAO:DataProvider
{
	public LoaiTaiKhoanDAO()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public ArrayList LayMang_LoaiTaiKhoan()
    {
        connect();
        ArrayList arr = new ArrayList();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Select_LoaiTaiKhoan", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                LoaiTaiKhoanDTO obj = new LoaiTaiKhoanDTO();
                obj.MaloaiTaiKhoan = dr.GetInt32(0);
                obj.TenLoaiTaiKhoan = dr.GetString(1);
                arr.Add(obj);
            }
        }
        catch (Exception e)
        {
            throw e;
        }
        return arr;

    }
    public void insert(LoaiTaiKhoanDTO obj)
    {
        connect();

        try
        {
            SqlCommand cmd = new SqlCommand("sp_Insert_LoaiTaiKhoan", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@TenLoaiTaiKhoan", SqlDbType.NVarChar);
            cmd.Parameters["@TenLoaiTaiKhoan"].Value = obj.TenLoaiTaiKhoan.ToString();
            cmd.Parameters["@TenLoaiTaiKhoan"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void delete(int ma)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Delete_TaiKhoan", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaLoaiTaiKhoan", SqlDbType.Int);
            cmd.Parameters["@MaLoaiTaiKhoan"].Value = ma;
            cmd.Parameters["@MaLoaiTaiKhoan"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    public void update(LoaiTaiKhoanDTO obj)
    {
        connect();
        try
        {
            SqlCommand cmd = new SqlCommand("sp_Update_LoaiTaiKhoan", strCnn);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.Add("@MaLoaiTaiKhoan", SqlDbType.Int);
            cmd.Parameters["@MaLoaiTaiKhoan"].Value = obj.MaloaiTaiKhoan;
            cmd.Parameters["@MaLoaiTaiKhoan"].Direction = ParameterDirection.Input;

            cmd.Parameters.Add("@TenLoaiTaiKhoan", SqlDbType.NVarChar);
            cmd.Parameters["@TenLoaiTaiKhoan"].Value = obj.TenLoaiTaiKhoan.ToString();
            cmd.Parameters["@TenLoaiTaiKhoan"].Direction = ParameterDirection.Input;

            cmd.ExecuteNonQuery();

        }
        catch (System.Exception ex)
        {
            throw ex;
        }
    }
}
